isc.ClassFactory.defineClass('buildMenu', isc.TreeGrid);
isc.buildMenu.addProperties({
	//openerImage: OB.Styles.skinsPath + 'Default/org.openbravo.client.application/images/application-menu/iconFolder.png',
	nodeIcon: OB.Styles.skinsPath + 'Default/org.openbravo.client.application/images/application-menu/iconForm.png',
	folderIcon:OB.Styles.skinsPath + 'Default/org.openbravo.client.application/images/application-menu/iconFolder.png',
	recordClick  :function(viewer, node, recordNum, field, fieldNum, value, rawValue){
		
		var item = node.data;
		if(item.type=='folder'){//点击父菜单 不进入该事件   当点击 需要打开TAB VIEW  等等的时候才进入 
			return ;
		}
		
		var isClassicEnvironment = OB.Utilities.useClassicMode(item.windowId);
	    var selectedView = isc.addProperties({}, item);
	    if (item.tabId) {
	      selectedView = OB.Utilities.openView(item.windowId, item.tabId, item.title, null, null, item.icon, item.readOnly, item.singleRecord, null, item.editOrDeleteOnly);
	      selectedView.type = item.type;
	      selectedView.icon = item.icon;
	      if (selectedView) {
	        OB.RecentUtilities.addRecent('UINAVBA_MenuRecentList', selectedView);
	      }
	      return;
	    } else if (item.recentObject) {
	      selectedView = item.recentObject;
	      if (!selectedView.viewId) {
	        selectedView.viewId = 'OBClassicWindow';
	      }
	    } else if (item.manualUrl) {
	      if (item.manualProcessId) {
	        selectedView = {
	          viewId: 'OBClassicWindow',
	          obManualURL: item.manualUrl,
	          processId: item.manualProcessId,
	          id: item.manualProcessId,
	          command: 'DEFAULT',
	          tabTitle: item.title
	        };
	      } else if (item.processId) {
	        var viewName = item.modal ? 'OBClassicPopupModal' : 'OBPopupClassicWindow';
	        selectedView = {
	          viewId: viewName,
	          obManualURL: item.manualUrl,
	          processId: item.processId,
	          id: item.processId,
	          command: 'BUTTON' + item.processId,
	          tabTitle: item.title,
	          popup: true
	        };
	      } else if (item.formId) {
	        selectedView = {
	          viewId: 'OBClassicWindow',
	          obManualURL: item.manualUrl,
	          id: item.manualUrl,
	          formId: item.formId,
	          command: 'DEFAULT',
	          tabTitle: item.title
	        };
	      } else {
	        selectedView = {
	          viewId: 'OBClassicWindow',
	          obManualURL: item.manualUrl,
	          id: item.manualUrl,
	          command: 'DEFAULT',
	          tabTitle: item.title
	        };
	      }
	    } else if (item.externalUrl) {
	      selectedView = {
	        viewId: 'OBExternalPage',
	        contentsURL: item.externalUrl,
	        id: item.externalUrl,
	        command: 'DEFAULT',
	        tabTitle: item.title,
	        openLinkInBrowser: item.openLinkInBrowser
	      };
	    } else if (!item.processDefinitionId) {
	      // do nothing for param windows
	      selectedView = {
	        viewId: item.viewId,
	        tabTitle: item.title
	      };
	    }

	    selectedView.icon = item.icon;
	    selectedView.type = item.type;

	    selectedView = isc.addProperties({}, item, selectedView);

	    OB.RecentUtilities.addRecent('UINAVBA_MenuRecentList', selectedView);
	    if (selectedView.openLinkInBrowser && selectedView.viewId === 'OBExternalPage') {
	      if (selectedView.contentsURL.indexOf('://') === -1) {
	        selectedView.contentsURL = 'http://' + selectedView.contentsURL;
	      }
	      OB.ViewManager.recentManager.addRecent('OBUIAPP_RecentViewList', isc.addProperties({
	        icon: OB.Styles.OBApplicationMenu.Icons.externalLink
	      }, selectedView));
	      window.open(selectedView.contentsURL);
	    } else {
	      OB.Layout.ViewManager.openView(selectedView.viewId, selectedView);
	    }
	}
});
